<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #div1{
            width: 200px;
            height: 200px;
            background: lightblue;
        }
    </style>
    <script type="text/javascript">
       function getStyle(obj,name) {
           if(obj.currentStyle){
              return obj.currentStyle[width];//如果是IE， obj.currentStyle不为空，if语句为真
           }
           else {
              return getComputedStyle(obj,false)[name];//等于return getComputedStyle(obj,name).name
           }
       }

        window.onload = function ()
        {
            var oDiv = document.getElementById("div1");
            alert(getStyle(oDiv,'width'));
        };
    </script>
</head>
<body>
   <div id="div1"></div>
</body>
</html>